package com.ihteima.exception;

import com.ihteima.pojo.Response;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * ClassName: GlobalException
 * Package: com.ihteima.exception
 * Description:
 *
 * @Auther gongkaiming
 * @Create 2025/10/26 18:17
 * @Version 1.0
 */
@ControllerAdvice
@Slf4j
public class GlobalException {


    @ExceptionHandler({BizException.class})
    @ResponseBody
    public Response<Object> handlerBizException(HttpServletRequest request, BizException e) {
        log.warn("{} request fail, errorCode: {}, errorMessage: {}", request.getRequestURI(), e.getErrorCode(), e.getErrorMessage());
        return Response.fail(e);
    }
}
